#include "../Diagnostic/Diagnostic3D.h"
#include "../Parallel/ParallelMPI3D.h"

#include <algorithm>

Diagnostic3D::Diagnostic3D(PicParams* params_, ParallelMPI* pmpi_, Grid* grid_, PhysicalField* fields_, vector<Species*>* vecSpecies_, vector<Collision*>* vecCollision_, vector<PSI*>* vecPSI_) :
    Diagnostic(params_, pmpi_, grid_, fields_, vecSpecies_, vecCollision_, vecPSI_)
{
    dims_global.resize(3);
    dim_global = 1;
    for(int i = 0; i < 3; i++)
    {
        dims_global[i] = params->dims_space_global[i] + 1;
        dim_global *= dims_global[i];
    }

    dx = params->cell_length[0];
    dy = params->cell_length[1];
    dz = params->cell_length[2];
    dx_inv_   = 1.0/params->cell_length[0];
    dy_inv_   = 1.0/params->cell_length[1];
    dz_inv_   = 1.0/params->cell_length[2];

    ParallelMPI3D* pmpi3D = static_cast<ParallelMPI3D*>(pmpi);
    i_domain_begin = pmpi3D->getCellStartingGlobalIndex(0);
    j_domain_begin = pmpi3D->getCellStartingGlobalIndex(1);
    k_domain_begin = pmpi3D->getCellStartingGlobalIndex(2);

    n_species = params->species_param.size();
    particleFlux.resize(n_species);
    heatFlux.resize(n_species);
    particleFlux_global.resize(n_species);
    heatFlux_global.resize(n_species);

    for(int i_species = 0; i_species < n_species; i_species++)
    {
        particleFlux[i_species]         = new Field3D<double>(dims_global, ("particleFlux_"          + params->species_param[i_species].species_name).c_str());
        heatFlux[i_species]             = new Field3D<double>(dims_global, ("heatFlux_"              + params->species_param[i_species].species_name).c_str());
        particleFlux_global[i_species]  = new Field3D<double>(dims_global, ("particleFlux_global_"   + params->species_param[i_species].species_name).c_str());
        heatFlux_global[i_species]      = new Field3D<double>(dims_global, ("heatFlux_global_"       + params->species_param[i_species].species_name).c_str());
    }
}

